package com.ezops.poc.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.ezops.poc.bo.Asset;
import com.ezops.poc.bo.Client;

/**
 * DAO for accesing lookupable items.
 * 
 * @author vgaurav
 * 
 */
@Repository
public class UtilityDAO {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	private static final String GET_ALL_CLIENTS = "SELECT CLIENT_ID, CLIENT_NAME FROM EZOPSDB.CLIENT_LOOKUP";
	private static final String GET_ALL_ASSETS = "SELECT ASSET_ID, ASSET_NAME FROM EZOPSDB.ASSETLOOKUP";

	public UtilityDAO() {
	}

	public List<Client> getAllClients() {
		List<Client> results = jdbcTemplate.query(GET_ALL_CLIENTS,
				new RowMapper<Client>() {

					@Override
					public Client mapRow(ResultSet rs, int arg1)
							throws SQLException {
						Client client = new Client();
						client.setClientId(rs.getInt("CLIENT_ID"));
						client.setClientName(rs.getString("CLIENT_NAME"));
						return client;
					}
				});
		return results;

	}

	
	public List<Asset> getAllAssets() {
		List<Asset> results = jdbcTemplate.query(GET_ALL_ASSETS,
				new RowMapper<Asset>() {

					@Override
					public Asset mapRow(ResultSet rs, int arg1)
							throws SQLException {
						Asset asset = new Asset();
						asset.setAssetId(rs.getInt("ASSET_ID"));
						asset.setAssetName(rs.getString("ASSET_NAME"));
						return asset;
					}
				});
		return results;

	}

}
